package test.through.tree;

import java.math.BigDecimal;
import com.alibaba.fastjson.JSON;

import hyl.core.MyFun;
import hyl.core.MyMath;
import hyl.core.data.CcMap;
import hyl.core.data.IMap;
import hyl.base.flow.chart.CNode;
import hyl.base.flow.chart.CThrough;
import hyl.base.flow.chart.IWorker;


/**
 * <p>
 * className: demo
 * </p>
 * <p>
 * Description: TODO
 * </p>
 * 
 * @author: Administrator
 * @date: 2018年9月18日 下午4:32:03
 * @copyright: 2018 da you zou Inc. All rights reserved.
 */
public class demobonus {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		test添加节点时处理();
		//test添加完成后一次性处理();
		
	}
	public static void test添加完成后一次性处理() {
		CNode root1 = new CNode("1",null, initpp(null));
		CNode node2 = new CNode("2", root1, initpp("L"));
		CNode node3 = new CNode("3", node2, initpp("L"));
		CNode node4 = new CNode("4", root1, initpp("R"));
		CNode node5 = new CNode("5", node3, initpp("R"));
		CNode node6 = new CNode("6", node3, initpp("L"));
		CNode node7 = new CNode("7", node4, initpp("L"));
		CNode node8 = new CNode("8", node6, initpp("L"));
		CThrough add1 = new CThrough();
		
		CworkAdd1nNode addwork2= new CworkAdd1nNode();
		CThrough add2 = new CThrough();
		add2.addWork(addwork2);
		IWorker addwork1=(cnd,objs,parms)->{
			add2.througUp(cnd);
			return objs;
		};
		add1.addWork(addwork1);
		add1.througDown(root1);
		print(root1);
	}
	public static void test添加节点时处理() {
		// 监听体 添加 处理事件
		CThrough addthrough = new CThrough();
		addthrough.addWork(new CworkAdd1nNode());
		IWorker addlisten=(cnd,objs,pars)->{
			//INode pnd=(INode)objs[0];
			//MyFun.print(pnd.getId(),cur.getId());
			addthrough.througUp(cnd);
			return objs;
		};
		// 拼图
		CNode root1 = new CNode("1",null, initpp(null));
		CNode node2 = new CNode("2", root1, initpp("L"));
		CNode node3 = new CNode("3", node2, initpp("L"));
		CNode node4 = new CNode("4", root1, initpp("R"));
		CNode node5 = new CNode("5", node3, initpp("R"));
		CNode node6 = new CNode("6", node3, initpp("L"));
		CNode node7 = new CNode("7", node4, initpp("L"));
		CNode node8 = new CNode("8", node6, initpp("L"));
		System.out.println("-----------------------");
			print(root1);
	}

//初始化属性
	public static IMap<String, Object> initpp(String 位置) {
		BigDecimal firstcharge = BigDecimal.valueOf(1000);
		CcMap<String, Object> mpHashMap = new CcMap<String, Object>();
		mpHashMap.put("WZ", 位置);
		mpHashMap.put("收入", firstcharge);
		mpHashMap.put("L数量", 0);
		mpHashMap.put("L收入", MyMath.BD0);
		mpHashMap.put("R数量", 0);
		mpHashMap.put("R收入", MyMath.BD0);
		return mpHashMap;
	}

	public static void print(CNode root) {
		CThrough alllisten = new CThrough();
		IWorker wkIWork =(cur,value,pars)->{
			MyFun.print(cur.getId(),JSON.toJSONString(cur.getAttrs()));
			return value;
		};
		alllisten.addWork(wkIWork);
		try {
			alllisten.througDown(root);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


}
